-- SkySequenceList
-- create by chendh
-- 天空之城战斗的播放序列控制器

-- 播放序列控制器
SkySequenceList = class("SkySequenceList");

function SkySequenceList.create(attacker, defenser)
    local self = SkySequenceList.new();

    self.attackerSequenceList = SkySequence.new(attacker);
    self.defenserSequenceList = SkySequence.new(defenser);

    self.sequenceList = { self.attackerSequenceList, self.defenserSequenceList, };

    return self;
end

--构造函数
function SkySequenceList:ctor()
    -- 初始化
    self.sequenceList = {};
end

-- 播放序列
function SkySequenceList:play()
    local isAllFree = true;

    for _, sequence in ipairs(self.sequenceList) do
        if sequence then
            -- 如果当前是空闲状态则开始播放
            -- 如果不是空闲状态，则说明正在播放，那么新插入队列的自然就会一起被播放了，所以不需要主动开始
            if sequence.isFree then
                -- 播放一个序列
                sequence:play();
            end

            if not sequence.isFree then
                isAllFree = false;
            end
        end
    end

    if isAllFree then
        -- 如果全部是空闲状态，则说明都播放完毕了，那么开始下一行为吧
        EventMgr.fire(event.SKY_COMBAT_SEQUENCEN_FREE);
    else
        local uiCombat = UIMgr.getCurrentScene():getFormByName("UISkyCityCombat");
        performWithDelay(uiCombat, function()
            self:play();
        end, 0.1);
    end
end

-- 获取播放序列列表
function SkySequenceList:getSequenceList()
    return self.sequenceList;
end

-- 获取指定对象的播放序列
function SkySequenceList:getSequenceByFighter(fighter)
    for _, sequence in ipairs(self.sequenceList) do
        if sequence.fighter == fighter then
            return sequence;
        end
    end
end

-- 重置
function SkySequenceList:resetActionSequence()
    for _, sequence in ipairs(self.sequenceList) do
        -- 初始化
        sequence.actionSequence = {};
    end
end

return SkySequenceList;
